package com.lidx.back.statistics.controller.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.lidx.back.statistics.commons.Constants;
import com.lidx.back.statistics.commons.PageInfo;
import com.lidx.back.statistics.entity.FeedBack;
import com.lidx.back.statistics.service.IDictionaryService;
import com.lidx.back.statistics.service.IFeedbackService;

@Controller
@RequestMapping("/admin/feedback")
public class FeedbackAdminController {

	@Autowired
	private IFeedbackService feedbackService;
	
	@Autowired
	private IDictionaryService dictionaryService;
	
	@RequestMapping(value="list",method=RequestMethod.GET)
	public String listGet(Model model,@RequestParam(required=false,defaultValue="10") int pageSize,
			@RequestParam(required=false,defaultValue="1") int pageNo){
	    PageInfo pageInfo = feedbackService.queryFeedbacks(pageNo, pageSize);
		String imageUrlPrefix = dictionaryService.getValueByCode(Constants.IIS_IMAGES_URL_PREFIX_CODE);
		if(pageInfo != null){
			model.addAttribute("pageInfo", pageInfo);
			model.addAttribute("prefixUrl", imageUrlPrefix);
		}
		return "feedback/list";
	}
	
	@RequestMapping(value="list",method=RequestMethod.POST)
	public String list(Model model,@RequestParam(required=false,defaultValue="10") int pageSize,
			@RequestParam(required=false,defaultValue="1") int pageNo){
		//List<FeedBack> feedBacks = feedbackService.getFeedBacks();
		 PageInfo pageInfo = feedbackService.queryFeedbacks(pageNo, pageSize);
		String imageUrlPrefix = dictionaryService.getValueByCode(Constants.IIS_IMAGES_URL_PREFIX_CODE);
		if(pageInfo != null){
			model.addAttribute("pageInfo", pageInfo);
			model.addAttribute("prefixUrl", imageUrlPrefix);
		}
		model.addAttribute("pageSize", pageSize);
		return "feedback/list";
	}
}
